package com.datax.web.web;

import net.sf.json.JSONArray;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Discript：
 *
 * @author <a href="787827967@qq.com">杨波</a>
 * @date 创建时间：2019/6/10 16:32
 */
@RestController
public class ComputerStatusController {

    @RequestMapping(value = "/computer/w/process", method = RequestMethod.GET)
    public String getComputerWProcess() {
        Runtime runtime = Runtime.getRuntime();
        List tasklist = new ArrayList();
        try{
            Process process = runtime.exec("tasklist");
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String s = "";
            while ((s = br.readLine()) != null) {
                if ("".equals(s)) {
                    continue;
                }
                tasklist.add(s+" ");
            }
            System.out.println(JSONArray.fromObject(tasklist).toString());
        }catch (Exception e){

        }
        return JSONArray.fromObject(tasklist).toString();
    }
    @RequestMapping(value = "/computer/l/process", method = RequestMethod.GET)
    public String getComputerLProcess() {
        return "";
    }
}
